﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SyndicateDAO.DAO;
using SyndicateDAO.DatabaseObject;

namespace SyndicateBusiness.Classes
{
    public class EventLogBL
    {
        private EventLogDAO EventLogDAO = new EventLogDAO();

        public IQueryable<eventLog> GetAllBySyndicateId(int sId)
        {
            return EventLogDAO.SelectAll().Where(c => c.syndicateId == sId);
        }
        public IQueryable<eventLog> GetAllByUserId(int uId)
        {
            return EventLogDAO.SelectAll().Where(c => c.userId == uId);
        }




        public void InsertEntry(user u, string desc, string type = eventLog.eventType.CHANGE)
        {
            eventLog l = new eventLog();
            l.userId = u.id;
            l.syndicateId = u.syndicateId;
            l.dateCreated = DateTime.Now;
            l.description = desc;
            l.type = type;
            this.EventLogDAO.Insert(l);
        }

        public eventLog GetLastEntry(int syndicateId)
        {
            return GetAllBySyndicateId(syndicateId).Where(l=>l.type == eventLog.eventType.CHANGE).OrderByDescending(l => l.dateCreated).FirstOrDefault();
        }

        public bool InsertEntry(eventLog l)
        {
            return EventLogDAO.Insert(l);
        }
        public bool UpdateEntry()
        {
            return EventLogDAO.Update();
        }
        public bool DeleteEntry(eventLog l)
        {
            return EventLogDAO.Delete(l);
        }

    }
}
